package com.shengwei.truck.driver.view.ui.common;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import com.shengwei.truck.driver.R;

/**
 * 我的提醒框
 */
public class MyAlertDlg {
    private static AlerClickInterface mAlertInterface;

    public interface AlerClickInterface{
        abstract void cancel();
        abstract void sure();
    }
    /**
     * 警告提示,系统自带对话框
     */
    static public void alertConfirmTip(int titleId, int msgId, Context context,AlerClickInterface alerClickInterface)
    {
        mAlertInterface = alerClickInterface;
        AlertDialog.Builder b = new AlertDialog.Builder(context);
        if(titleId != 0)
             b.setTitle(titleId);
        b.setCancelable(false);
        b.setMessage(msgId);
        b.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mAlertInterface.sure();
            }
        });
        b.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mAlertInterface.cancel();
                }
            });

        AlertDialog alertDialog = b.create();
        alertDialog.show();
        //修改对话框按钮文字颜色START
        int colorPrimary = context.getResources().getColor(R.color.colorPrimary);
        int colorDescribe = context.getResources().getColor(R.color.describe_color);
        alertDialog.getButton(alertDialog.BUTTON_POSITIVE).setTextColor(colorPrimary);
        alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(colorDescribe);
        //修改对话框按钮文字颜色end
        return;
    }


    /**
     * 警告提示
     */
    static public void alertConfirmTip(int titleId, String msgId, Context context,AlerClickInterface alerClickInterface)
    {
        mAlertInterface = alerClickInterface;
        AlertDialog.Builder b = new AlertDialog.Builder(context);
        if(titleId != 0)
            b.setTitle(titleId);
        b.setCancelable(false);
        b.setMessage(msgId);
        b.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mAlertInterface.sure();
            }
        });

        AlertDialog alertDialog = b.create();
        alertDialog.show();
        //修改对话框按钮文字颜色START
        int colorPrimary = context.getResources().getColor(R.color.colorPrimary);
        int colorDescribe = context.getResources().getColor(R.color.describe_color);
        alertDialog.getButton(alertDialog.BUTTON_POSITIVE).setTextColor(colorPrimary);
        alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(colorDescribe);
        //修改对话框按钮文字颜色end
        return;
    }
    /**
     * 警告提示，自定义提示框布局
     */
    static public void alertConfirmTip2(int titleId, String msg, Context context,AlerClickInterface alerClickInterface) {
        View view  = LayoutInflater.from(context).inflate(R.layout.alert_layout, null);
        mAlertInterface = alerClickInterface;
        AlertDialog.Builder b = new AlertDialog.Builder(context);
        if(titleId != 0)
            b.setTitle(titleId);
        b.setCancelable(false);
        b.setView(view);
        AlertDialog alertDialog = b.create();
        alertDialog.show();
        //alertDialog.getWindow().setBackgroundDrawableResource(R.drawable.bg_popwindow);
        //alertDialog.getWindow().setContentView(view);
        Button btSure = view.findViewById(R.id.btSure);
        btSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mAlertInterface.sure();
                if(alertDialog != null){
                    alertDialog.dismiss();
                }
            }
        });
        Button btCancel = view.findViewById(R.id.btCancel);
        btCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(alertDialog != null){
                    alertDialog.dismiss();
                }
            }
        });
        return;
    }
}
